#include "drv_dma.h"
#include "stm32f4xx.h"
int drv_dma_init(uint32_t *src,uint32_t *drc,uint32_t size)
{
	DMA_InitTypeDef DMA_InitStruct;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
	DMA_InitStruct.DMA_BufferSize =size;//需要搬运的数量
	DMA_InitStruct.DMA_Channel = DMA_Channel_0;//通道0
	DMA_InitStruct.DMA_DIR = DMA_DIR_MemoryToMemory;//数据传输方向内存到内存
	DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Disable;//直接模式
	DMA_InitStruct.DMA_Memory0BaseAddr = (uint32_t)drc;//目标地址
	DMA_InitStruct.DMA_MemoryBurst = DMA_MemoryBurst_Single;//单次突发传输
	DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;//数据传输大小
	DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;//目标地址自增
	DMA_InitStruct.DMA_Mode = DMA_Mode_Normal;//普通模式
	
	DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)src;//数据源地址
	DMA_InitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//单次突发传输
	DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;//数据传输大小
	DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Enable;//数据源地址自增
	DMA_InitStruct.DMA_Priority = DMA_Priority_High;//优先级为高
	DMA_Init(DMA2_Stream0, &DMA_InitStruct); //初始化DMA2，使配置生效
	DMA_Cmd(DMA2_Stream0, ENABLE); //开启DMA功能
}

extern uint32_t data_src[10];//源数据
extern uint32_t data_drc[10];//目标
/****************************************************
函数名：drv_dma_compare

功  能：验证DMA数据搬运是否正确

输入参数：无

输出参数：无

其它说明：

******************************************************/

void drv_dma_compare(void)
{
	int i=0;
	for(i=0;i<10;i++)
	{
		if(data_drc[i]!= data_src[i])
		{
			printf("data_err[%d] data=0x%x\r\n",i,data_drc[i]);
			return;
		}
		printf("data_drc[i]=0x%x\r\n",data_drc[i]);
	}

}

